package Member;

import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JLabel;

import java.awt.Font;
import java.awt.Color;
import java.awt.TextArea;
import javax.swing.JTextArea;
import java.awt.Dimension;

public class Output extends JPanel {
	private JScrollPane scrollPane;
	private JLabel lblNewLabel;
	private JLabel lblMembers;
	
	Data6[] d;
	private JTextArea textArea;

	/**
	 * Create the panel.
	 */
	public Output() {
		setSize(new Dimension(450, 500));
		setBackground(new Color(250, 128, 114));
		setLayout(null);
		add(getScrollPane());
		add(getLblMembers());

	}
	
	
	private JScrollPane getScrollPane() {
		if (scrollPane == null) {
			scrollPane = new JScrollPane();
			scrollPane.setSize(new Dimension(420, 450));
			scrollPane.setBounds(12, 46, 376, 344);
			scrollPane.setColumnHeaderView(getLblNewLabel());
			scrollPane.setViewportView(getTextArea());
		}
		return scrollPane;
	}
	private JLabel getLblNewLabel() {
		if (lblNewLabel == null) {
			
			lblNewLabel = new JLabel("Name        Address        Phone        Email                Age");
		}
		return lblNewLabel;
	}
	private JLabel getLblMembers() {
		if (lblMembers == null) {
			lblMembers = new JLabel("Members");
			lblMembers.setFont(new Font("Segoe Print", Font.BOLD, 16));
			lblMembers.setBounds(12, 10, 98, 26);
		}
		return lblMembers;
	}
	private JTextArea getTextArea() {
		if (textArea == null) {
			textArea = new JTextArea();
		}
		return textArea;
	}
	public void setD(Data6[] d){
		this.d=d;
		
		textArea.setText("");
		
		for (int i=0;i<d.length;i++){
			//데이터의 유무에 따라 데이터를 출력해야 하는데, 
			//break; 를 사용하면 for 문을 벗어나게 된다.
			//연속적인 데이터만 있을때는 break;를 사용해도 좋지만
			//만약 데이터가 배열속에 드문드문 들어있을 때에는 continue;를 사용하는 것이 좋다. 
			if(d[i] == null) continue;
			String str1 = String.format("%-10s%-10s%-8s%-16s%-4s",d[i].name,d[i].address,d[i].number,d[i].email,d[i].age);
			textArea.append(str1);
			
			//textArea.append(d[i].name +"    " + d[i].address+"    " +d[i].number+"    " +d[i].email+"    " +d[i].age); 
			textArea.append("\n");
		}		
	}
}
